package com.sopra.tecnica.poc.server.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sopra.tecnica.poc.server.dao.ItemDao;
import com.sopra.tecnica.poc.server.dao.OrderDao;
import com.sopra.tecnica.poc.server.dao.SizeDao;
import com.sopra.tecnica.poc.server.entity.SizeEntity;

@Service
public class SizeService {

	@Autowired
	private SizeDao sizeDao;
	
	@Autowired
	private ItemDao itemDao;
	
	@Autowired
	private OrderDao orderDao;

	public List<SizeEntity> findItemSizes(String orderNum, String lineNum) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("company", "001");
		map.put("orderNumber", orderNum);
		map.put("itemLineNumber", lineNum);

		List<SizeEntity> result = sizeDao.selectWithGenericCriterias(map);
		return result;
	}

	public void update(Integer orderNum, Integer lineNum, Integer sizeId, Integer qty,
			Integer discount, Integer netPrice) {
		sizeDao.update(orderNum, lineNum, sizeId, qty, discount, netPrice);
		itemDao.updateSumQty(orderNum, lineNum);
		orderDao.updateSumQty(orderNum);
		
		itemDao.updateSumPrice(orderNum, lineNum);
		orderDao.updateSumPrice(orderNum);
	}
}
